package com.shilan.administrator.qintfm.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.shilan.administrator.qintfm.MainActivity;
import com.shilan.administrator.qintfm.R;
import com.shilan.administrator.qintfm.Utils.MediaUtils;
import com.shilan.administrator.qintfm.adapter.MusicListFragmentAdapter;
import com.shilan.administrator.qintfm.beans.SongInfo;
import com.shilan.administrator.qintfm.fragment.tabhostFragment.MineFragment;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/14.
 */
public class MusicLIstFragment extends BaseFragment implements View.OnClickListener {
    private ListView musiclistView;
    private ArrayList<SongInfo> songInfos;
    private MainActivity mainActivity;
    private MusicListFragmentAdapter adapter;




//    public static MusicLIstFragment newInstance() {
//        MusicLIstFragment musicLIstFragment = new MusicLIstFragment();
//
//        return  musicLIstFragment;
//    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        //TODO
        mainActivity = (MainActivity) context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_musiclist,null);
        musiclistView = (ListView) view.findViewById(
                R.id.mymusiclist_fragment_listview);

        view.findViewById(R.id.musiclist_rtn_iv).setOnClickListener(this);
            loadData();
            return view;

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        songInfos = MediaUtils.getSongInfos(mainActivity);
        adapter = new MusicListFragmentAdapter(mainActivity,songInfos);
        musiclistView.setAdapter(adapter);

    }

    /**
     * 加载本地音乐的列表
     * **/
    private  void loadData() {
        //TODO 下列第一个括号里面应当传的是一个context,


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.musiclist_rtn_iv:
                goBack();
        }
    }


}
